//
// Created by xm on 2024/4/29.
//

#include "test04.h"
#include "iostream"
#include "Person.h"
#include "MyArray.h"

using namespace std;
using namespace Test04;

static void demo01()
{
    Person per1("Simon", 36, 181.1);
    cout << per1.description() << endl;
    // 匿名对象
    Person();

    // 拷贝对象
    Person per2(per1);
    cout << per2.description() << endl;
}

Person func2()
{
    Person p;
    cout << "func2 " << &p << endl;
    return p;
}

static void demo02()
{
    Person p = func2();
    cout << "test02 " << &p << endl;
}

static void demo03()
{
    Person* p = new Person("Tom", 31, 181.1);
    cout << "demo03 " << p->description() << endl;
    delete p;
}


static void demo04()
{

    cout << "demo04 " << sizeof(Person) << endl;
}


static void demo05()
{

    cout << "demo05 " << endl;

    MyArray* m = new MyArray(10,0);
    m->pushFront(10);
    m->insert(3, 3);
    m->insert(5, 5);
    m->pushBack(10);
    m->toPrint();

    cout << "---- popFront ---- " << endl;
    m->popFront();
    m->toPrint();
    cout << "---- popBack ---- " << endl;
    m->popBack();
    m->toPrint();

}

// 运算符重载
static void demo06(){

    Person p1("Simon");
    Person p2("Semon");

    p1.toPrint();
    p2.toPrint();

    p1 = p2;

    p1.toPrint();
    p2.toPrint();


}

// 数组下标运算符重载
static void demo07(){
    MyArray m(10,0);


    cout << "---- 1 ---- " << endl;
    for (int i = 0; i < 10; i++) {
        m[i] = i + 10;
    }

    m.toPrint();

    cout << "---- 2 ---- " << endl;
    MyArray m2 = m;
    m2.toPrint();

}


static void demo08(){
    MyArray* m = new MyArray(10,0);


    cout << "---- 1 ---- " << endl;
    for (int i = 0; i < 10; i++) {
        (*m)[i] = i + 10;
    }

    m->toPrint();

    cout << "---- 2 ---- " << endl;
    MyArray* m2 = new MyArray(10);
    *m2 = *m;
    m2->toPrint();
    delete m;
    delete m2;

}


static void demo09()
{
    MyArray m(10);

    cout << "---- 1 ---- " << endl;
    for (int i = 0; i < 10; i++) {
        m[i] = i + 10;
    }

    m.toPrint();

    cout << "---- 2 ---- " << endl;
    MyArray m2(10);
    m2 = m;
    m2.toPrint();

}
// 智能指针
static void demo10()
{
    Person *p = new Person("Simon");
    PersonSmartPoint  smp(p);
}


class A{
public:
    A(){
        cout << "A 构造" << endl;
    }
    ~A(){
        cout << "A 析构" << endl;
    }

};

class B{
public:
    B(){
        cout << "B 构造" << endl;
    }
    ~B(){
        cout << "B 析构" << endl;
    }
};

class C{
public:
    C(){
        cout << "C 构造" << endl;
    }
    ~C(){
        cout << "C 析构" << endl;
    }
};

class D :public A{
public:
    D(){
        cout << "D 构造" << endl;
    }
    ~D(){
        cout << "D 析构" << " b<"<< &b << ">" <<endl;
    }
private:
    B b;
};
/**
 * 调用顺序
 */
void demo11(){
    D d;
}

class Demo12_A{
public:
    Demo12_A(){
        name = "A";
    }
    ~Demo12_A(){

    }

public:
    string name;
};

class Demo12_B: virtual public Demo12_A{
public:
    Demo12_B(){
//        name = "B";
    }
    ~Demo12_B(){

    }
};

class Demo12_C: virtual public Demo12_A{
public:
    Demo12_C(){
//        name = "C";
    }
    ~Demo12_C(){

    }
};

class Demo12_D :  public Demo12_B , public Demo12_C{
public:
    Demo12_D(){
//        name = "D";
    }
    ~Demo12_D(){

    }
public:
    void toPrint(){
        cout << name << endl;
    }
    // 雷和对象。累的封装，初始化和清理的概念（了解）
    // 后早函数和析构函数（重点）
    // 构造函数的分类及调用（重点）
    // 匿名对象
    // 初始化列表
    // explicit的作用
    // C++的堆区空间的申请和释放
    // 静态联编和动态联编
    // this指针
    // 常函数和常对象（重点）
    // 单例模式
    // 数组类
    // 运算符重载
    // 加号运算符重载


};


void demo12()
{
    Demo12_D d;
    d.toPrint();
}

void test04()
{
    cout << "test04" << endl;

//    cout << "------ demo02 ------" << endl;
//    demo02();
//
//    cout << "------ demo03 ------" << endl;
//    demo03();

//    cout << "------ demo05 ------" << endl;
//    demo05();

//    cout << "------ demo06 ------" << endl;
//    demo06();

//    cout << "------ demo07 ------" << endl;
//    demo07();
//
//    cout << "------ demo08 ------" << endl;
//    demo08();
//    cout << "------ demo09 ------" << endl;
//    demo09();

//    cout << "------ demo10 ------" << endl;
//    demo10();

//    cout << "------ demo11 ------" << endl;
//    demo11();

    cout << "------ demo12 ------" << endl;
    demo12();



}

